package com.himore.api.web.controller.modules;

import java.util.List;

import com.himore.api.web.model.TSysUser;
import com.himore.api.web.service.ITSysUserService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.himore.api.common.annotation.Log;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.common.core.page.TableDataInfo;

/**
 * 用户库信息Controller
 * 
 * @author ruoyi
 * @date 2021-02-01
 */
@Api(tags = "用户信息管理")
@RestController
@RequestMapping("/user")
public class TSysUserController extends BaseController
{
    @Autowired
    private ITSysUserService tSysUserService;

    /**
     * 查询用户库信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TSysUser tSysUser)
    {
        startPage();
        List<TSysUser> list = tSysUserService.selectTSysUserList(tSysUser);
        return getDataTable(list);
    }

    /**
     * 导出用户库信息列表
     */
    @Log(title = "用户库信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSysUser tSysUser)
    {
        List<TSysUser> list = tSysUserService.selectTSysUserList(tSysUser);
        ExcelUtil<TSysUser> util = new ExcelUtil<TSysUser>(TSysUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取用户库信息详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return AjaxResult.success(tSysUserService.selectTSysUserById(userId));
    }


    /**
     * 获取用户库信息详细信息
     */
    @GetMapping(value = "/getUserInfo")
    public AjaxResult getUserInfo(@RequestParam("phoneNum") String phoneNum)
    {
        return AjaxResult.success(tSysUserService.selectTSysUserByPhone(phoneNum));
    }

    /**
     * 新增用户库信息
     */
    @Log(title = "用户库信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody TSysUser tSysUser)
    {
        return toAjax(tSysUserService.insertTSysUser(tSysUser));
    }

    /**
     * 修改用户库信息
     */
    @Log(title = "用户库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSysUser tSysUser)
    {
        return toAjax(tSysUserService.updateTSysUser(tSysUser));
    }

    /**
     * 删除用户库信息
     */
    @Log(title = "用户库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(tSysUserService.deleteTSysUserByIds(userIds));
    }
}
